package com.lwj.liwanjia.adapter.indent;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.adapter.IndentAdapter;
import com.lwj.liwanjia.adapter.IndentListAdapter;
import com.lwj.liwanjia.bean.MyIndentBean;
import com.lwj.liwanjia.view.activity.indent.UnpaidActivity;
import com.lwj.liwanjia.view.activity.myindent.tuikuantuihuo.ApplyStatusActivity;
import com.lwj.liwanjia.view.activity.work.shang_jia.ding_dan.tui_huo_tui_kuan.THXQActivity;
import com.superrecycleview.superlibrary.adapter.BaseViewHolder;
import com.superrecycleview.superlibrary.adapter.SuperBaseAdapter;
import com.superrecycleview.superlibrary.recycleview.SuperRecyclerView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/9/25.
 */

public class ReturnAdapter extends SuperBaseAdapter<MyIndentBean.DataBean> {
    private Context mContext;

    public ReturnAdapter(Context context, List<MyIndentBean.DataBean> data) {
        super(context, data);
        this.mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder holder, MyIndentBean.DataBean item, int position) {
        holder.setOnClickListener(R.id.tv_quxiao_indent, new OnItemChildClickListener());
        holder.setOnClickListener(R.id.tv_delete_indent, new OnItemChildClickListener());
        final MyIndentBean.DataBean.GoodsBean goods = item.getGoods();
        TextView tvState = holder.getView(R.id.tv_state);
        tvState.setTextSize(14);
        if(goods.getStatus().equals("退款退货中")||goods.getStatus().equals("换货中")||goods.getStatus().equals("退款中")){
            holder.setText(R.id.tv_state, goods.getStatus());
        }else{
            holder.setText(R.id.tv_state, goods.getStatus().replace("中", ""));
        }
        if (goods.getStatus().equals("正在申请(待发货)") || goods.getStatus().equals("正在申请(退款中)") ||
                goods.getStatus().equals("正在申请(换货中)") || goods.getStatus().equals("正在申请(退款退货中)")) {
            holder.setTextColor(R.id.tv_state, mContext.getResources().getColor(R.color.colorFF3B15))
                    .setVisible(R.id.ll_fukuan, false)
                    .setVisible(R.id.rl_indent_btn, true)
                    .setVisible(R.id.tv_delete_indent, true)
                    .setText(R.id.tv_delete_indent, "取消申请")
                    .setText(R.id.tv_quxiao_indent, "联系商家");
        } else if (goods.getStatus().equals("已同意(退款中)") || goods.getStatus().equals("已同意(换货中)")
                || goods.getStatus().equals("已同意(退款退货中)")) {
            holder.setTextColor(R.id.tv_state, mContext.getResources().getColor(R.color.colorFF3B15))
                    .setVisible(R.id.ll_fukuan, false)
                    .setVisible(R.id.rl_indent_btn, true)
                    .setVisible(R.id.tv_delete_indent, true)
                    .setText(R.id.tv_delete_indent, "取消申请")
                    .setText(R.id.tv_quxiao_indent, "填写物流");
        }
        else if (goods.getStatus().equals("已换货") || goods.getStatus().equals("已退款退货") || goods.getStatus().equals("已退款(已完成)") || goods.getStatus().equals("已退款(待发货)")) {
            if (goods.getStatus().equals("已退款(已完成)")) {
                holder.setText(R.id.tv_state, "已退款");
            }
            holder.setTextColor(R.id.tv_state, mContext.getResources().getColor(R.color.colorFF3B15))
                    .setVisible(R.id.ll_fukuan, false)
                    .setVisible(R.id.rl_indent_btn, true)
                    .setVisible(R.id.tv_delete_indent, false)
                    .setText(R.id.tv_quxiao_indent, "退款详情");
        } else {
            holder.setTextColor(R.id.tv_state, mContext.getResources().getColor(R.color.colorFF3B15))
                    .setVisible(R.id.ll_fukuan, false)
                    .setVisible(R.id.rl_indent_btn, true)
                    .setVisible(R.id.tv_delete_indent, false)
                    .setText(R.id.tv_quxiao_indent, "查看物流");
        }
        if (item.getTitle().equals("购物")) {
            holder.setText(R.id.tv_market, goods.getShopname())
                    .setText(R.id.tv_shangcheng_number, "共" + goods.getAmount() + "件商品 合计：")
                    .setText(R.id.tv_shangcheng_price, "￥" + goods.getTotalpay() + "(含运费￥0.00)");
            Glide.with(mContext).load(goods.getShopimage()).error(R.mipmap.shop_image_2).into((ImageView) holder.getView(R.id.iv_market));
            SuperRecyclerView rlvGouwuche = holder.getView(R.id.rlv_gouwuche);
            LinearLayoutManager manager = new LinearLayoutManager(mContext);
            manager.setOrientation(LinearLayoutManager.VERTICAL);
            rlvGouwuche.setLayoutManager(manager);
            rlvGouwuche.setRefreshEnabled(false);
            rlvGouwuche.setLoadMoreEnabled(false);
            ShopUnpaidAdater1 adapter = new ShopUnpaidAdater1(mContext, goods.getCommodity(), false);
            rlvGouwuche.setAdapter(adapter);
            adapter.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(View view, Object item, int position1) {
                    Intent i = new Intent(mContext, ApplyStatusActivity.class);
                    i.putExtra("tradeid", goods.getTradeId());
                    i.putExtra("phone", (String) goods.getShoptel());
                    mContext.startActivity(i);
                }
            });
        }
    }

    @Override
    protected int getItemViewLayoutId(int position, MyIndentBean.DataBean item) {
        if (item.getTitle().equals("购物")) {
            return R.layout.unpaid_item;
        }
        return 0;
    }
}
